import { getAlbumCount } from './index'
import { transformTime1, timeTransformData } from '@/utils/util'

export const transAlbumDetail = async (res) => {
  const { data: { album, songs } } = res
  const { id, name, description, picUrl, publishTime, alias, artists } = album
  const artistsList = artists.map(item => ({
    id: item.id,
    name: item.name
  } as Artists))
  const publish = timeTransformData(publishTime)
  const aliasStr = alias.length ? '(' + alias.join('/') + ')' : ''
  const { data: { shareCount, subCount, commentCount } } = await getAlbumCount(id)
  const songsList = songs.map(item => {
    const { al: { name: alName, id: alId }, ar, dt, id, name, mv, pop } = item
    const artists = ar.map(artist => ({ id: artist.id, name: artist.name }))
    const duration = transformTime1(dt)
    return {
      id,
      name,
      alId,
      alName,
      artists,
      duration,
      mv,
      pop
    } as PlaylistSongDetail
  })
  return {
    album: {
      id,
      name,
      description,
      picUrl,
      aliasStr,
      artists: artistsList,
      publishTime: publish,
      shareCount,
      commentCount,
      subCount
    } as AlbumDetail,
    songs: songsList
  }
}
